﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using Tools;
using Tour.DAL;

namespace Tour.BLL
{
    /// <summary>
    /// Summary description for TblTourDetail
    /// </summary>
    public class TblTourDetailManagerBase
    {
        public TblTourDetailManagerBase()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public void InsertUpdate(TblTourDetailEntity item)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", item.Id));
            ls.Add(new SqlParameter("@TourId", item.TourId));
            ls.Add(new SqlParameter("@Name", item.Name));
            ls.Add(new SqlParameter("@Description", item.Description));
            ls.Add(new SqlParameter("@DisplayOrder", item.DisplayOrder));
            ls.Add(new SqlParameter("@CreatedDate", item.CreatedDate));
            SqlParameter[] sqlparam = ls.ToArray();
            SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_InsertUpdateTblTourDetail", sqlparam);
        }
        public void InsertUpdate(int Id, int TourId, string Name, string Description, int DisplayOrder, System.DateTime CreatedDate)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            ls.Add(new SqlParameter("@TourId", TourId));
            ls.Add(new SqlParameter("@Name", Name));
            ls.Add(new SqlParameter("@Description", Description));
            ls.Add(new SqlParameter("@DisplayOrder", DisplayOrder));
            ls.Add(new SqlParameter("@CreatedDate", CreatedDate));
            SqlParameter[] sqlparam = ls.ToArray();
            SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_InsertUpdateTblTourDetail", sqlparam);
        }
        public void Delete(int Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_DeleteTblTourDetail", sqlparam);
        }
        public TblTourDetailEntity GetTblTourDetailEntity(DataRow dr)
        {
            TblTourDetailEntity item = new TblTourDetailEntity();            
            if (dr.Table.Columns.Contains("Id"))
                item.Id = dr["Id"].ToInt();              
            if (dr.Table.Columns.Contains("TourId"))
                item.TourId = dr["TourId"].ToInt();              
            if (dr.Table.Columns.Contains("Name"))
                item.Name = dr["Name"].ToString();              
            if (dr.Table.Columns.Contains("Description"))
                item.Description = dr["Description"].ToString();              
            if (dr.Table.Columns.Contains("DisplayOrder"))
                item.DisplayOrder = dr["DisplayOrder"].ToInt();              
            if (dr.Table.Columns.Contains("CreatedDate"))
                item.CreatedDate = dr["CreatedDate"].ToString().ToDateTime("vi-VN");            
            return item;
        }        
        public DataTable SelectOneRDT(int Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            return SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblTourDetail", sqlparam);
        }
        public TblTourDetailEntity SelectOne(int Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            DataTable dt = SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblTourDetail", sqlparam);
            if(dt!=null && dt.Rows.Count>0)
                return GetTblTourDetailEntity(dt.Rows[0]);
            return null;
        }
        public DataTable SelectAllRDT()
        {
            return SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblTourDetailsAll", null);
        }
        public List<TblTourDetailEntity> SelectAll()
        {
            List<TblTourDetailEntity> lsresult= new List<TblTourDetailEntity>();
            DataTable dt =  SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblTourDetailsAll", null);
            if (dt != null && dt.Rows.Count > 0)
                for (int i = 0; i < dt.Rows.Count; i++)
                    lsresult.Add(GetTblTourDetailEntity(dt.Rows[i]));            
            return lsresult;
        }
    }
}

